package com.example.widgethost;

import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
import android.widget.LinearLayout;

import com.example.widgethost.base.CacheContainerConstructor;
import com.example.widgethost.base.Config;

public class HostConstructor extends CacheContainerConstructor<LinearLayout, LinearLayout.LayoutParams, LauncherAppWidgetHost> {

    /**
     * contructor.
     *
     * @param context      context
     * @param linearLayout container layout
     */
    public HostConstructor(Context context, LinearLayout linearLayout) {
        super(context, linearLayout);
    }

    /**
     * get target provider info.
     *
     * @return target provider info array
     */
    @Override
    protected String[] getTargetProviderInfo() {
        return Config.PROVIDER_INFO_ARRAY;
    }

    /**
     * get container layout params.
     *
     * @param appWidgetProviderInfo app widget provider info
     * @return container layout params
     */
    @Override
    protected LinearLayout.LayoutParams getContainerLayoutParams(AppWidgetProviderInfo appWidgetProviderInfo) {
        int minWidth = LinearLayout.LayoutParams.WRAP_CONTENT;
        int minHeight = LinearLayout.LayoutParams.WRAP_CONTENT;
        if (appWidgetProviderInfo != null) {
            minWidth = appWidgetProviderInfo.minWidth;
            minHeight = appWidgetProviderInfo.minHeight;
        }
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(minWidth, minHeight);
        return layoutParams;
    }

    /**
     * contruct app widget host.
     *
     * @return app widget host
     */
    @Override
    protected LauncherAppWidgetHost contructAppWidgetHost() {
        return new LauncherAppWidgetHost(context);
    }

}
